home *** CD-ROM | disk | FTP | other *** search
/ ...taking it to the Macs! / ...taking it to the Macs!.iso / Extras / ActiveX Mac SDK / ActiveX SDK / Sample Controls / BDiamond / BDUtils.cp < prev    next >
Encoding:
Text File  |  1996-12-20  |  1.9 KB  |  98 lines  |  [TEXT/CWIE]

  1. #include "ocheaders.h"
  2. #include "CBaseControl.h"
  3. #include "FnAssert.h"
  4. #include "BDAssert.h"
  5. #include "BDUtils.h"
  6.  
  7. ///////////////////////////////////////////////////////////////////////////////
  8. //
  9. // Global functions
  10. //
  11.  
  12. ///////////////////////////////////////////////////////////////////////////////
  13. //
  14. // GetObjectName
  15. //
  16.  
  17. void GetObjectName (IUnknown* source, char * name)
  18. {
  19.     assert(name != NULL);
  20.     
  21.     IControl*        sourceObject = nil;
  22.     char            sourceName[Str255BufferLength];
  23.     
  24.     if (source)
  25.         source->QueryInterface(IID_IControl, &sourceObject);
  26.     
  27.     if (sourceObject) 
  28.     {
  29.         sourceObject->GetID(Str255StringLength, sourceName);
  30.         strcpy((char *) name, sourceName);
  31.         sourceObject->Release();
  32.     }
  33.     else
  34.     {
  35.         strcpy(name, "");
  36.     }
  37. }
  38.  
  39. ///////////////////////////////////////////////////////////////////////////////
  40. //
  41. // GetObjectID
  42. //
  43.  
  44. void GetObjectID (IUnknown* source, char * id)
  45. {
  46.     assert(id != NULL);
  47.     
  48.     IControl*        sourceObject = nil;
  49.     char            sourceID[Str255BufferLength];
  50.     
  51.     if (source)
  52.         source->QueryInterface(IID_IControl, &sourceObject);
  53.     
  54.     if (sourceObject) 
  55.     {
  56.         sourceObject->GetID(Str255StringLength, sourceID);
  57.         strcpy((char *) id, sourceID);
  58.         sourceObject->Release();
  59.     }
  60.     else
  61.     {
  62.         strcpy(id, "");
  63.     }
  64. }
  65.  
  66. ///////////////////////////////////////////////////////////////////////////////
  67. //
  68. // LoadPropertyString
  69. //
  70.  
  71. Boolean LoadPropertyString
  72.     (IPropertyBag *pPropertyBag, char * propertyName, char * propertyValue, long maxLength, IErrorLog *pErrorLog)
  73. {
  74.     VARIANT     v;
  75.     Boolean     success = false;
  76.     DWORD        length;
  77.  
  78. //    VariantInit(&v);
  79.  
  80.     v.vt = VT_BSTR;
  81.     v.bstrVal = NULL;
  82.     
  83.     pPropertyBag->Read(propertyName, &v, pErrorLog);
  84.     if (v.bstrVal)
  85.     {
  86.         length = *((LPDWORD) v.bstrVal) ;
  87.         if ( length < maxLength )
  88.             strcpy(propertyValue, v.bstrVal + sizeof(DWORD));
  89.         else
  90.             strncpy(propertyValue, v.bstrVal + sizeof(DWORD), maxLength);
  91.         CoTaskMemFree(v.bstrVal);
  92. //        VariantInit(&v);
  93.         success = true;
  94.     }
  95.    
  96.     return success;
  97. }
  98.